<?php
if (!defined('APPPATH')) exit('No direct script access allowed');

include_once(APPPATH.'libraries/api/core/MySQL.php');
include_once(APPPATH.'libraries/api/core/Services.php');

Class Language extends Services {
    
	public static function languageRecordUpdate($language_id, $column, $column_type, $value) {
		if(parent::checkArguments(array($language_id, $column, $column_type, $value))) {
			$query = "UPDATE `language` SET `$column` = " . MySQL::getColumnValueNotation($column_type, $value) . " WHERE `language_id` = $language_id; ";
			$result = MySQL::update($query);
			if(parent::check($result)) {
				return true;
			} else {
				return false;
			}
		} else {
			return false;
		}
	}    

	public static function languageGet($language_id) {
		if(parent::checkArguments($language_id)) {
			$query = "SELECT `language_id`, `name` FROM `language` WHERE `language_id` = $language_id; ";
			$result = MySQL::selectGetRow($query);
			if(parent::check($result)) {
				return $result;
			} else {
				return array();
			}
		} else {
			return array();
		}
	}

	public static function languageSet($name) {
		if(parent::checkArguments($name)) {
			$query = "INSERT INTO `language` (`name`) VALUES ('$name'); ";
			$result = MySQL::update($query);
			if(parent::check($result)) {
				return $result['last_insert_id'];
			} else {
				return false;
			}
		} else {
			return false;
		}
	}
        
	public static function languageDelete($language_id) {
		if(parent::checkArguments($language_id)) {
			$query = "UPDATE `content` SET `language_id` = NULL WHERE `language_id` = $language_id;
                                  DELETE FROM `language` WHERE `language_id` = $language_id; ";
			$result = MySQL::update($query);
			if(parent::check($result)) {
				return true;
			} else {
				return false;
			}
		} else {
			return false;
		}
	}        
	
	public static function languagesList() {
		$query = "SELECT `language_id`, `name` FROM `language`; ";
		$result = MySQL::selectGetArray($query);
		if(parent::check($result)) {
			return $result;
		} else {
			return array();
		}
	}
        
	public static function languagesSelect($language_id) {
		if(parent::checkArguments($language_id)) {
                        $query = "SELECT `language_id`, `name` FROM `language` WHERE `language_id` != $language_id; ";
                        $result = MySQL::selectGetArray($query);
                        if(parent::check($result)) {
                                return $result;
                        } else {
                                return array();
                        }
		} else {
			return array();
		}
	}        

}

?>
